import { ListenEventType, TouchEventType } from "../../util/defineConfig";
import View from "../../util/View";
import { Card } from "../gameModel";

const { ccclass, property } = cc._decorator;

@ccclass
export default class UICard extends View {

    private card: Card = null
    private selcted: boolean = false
    // 能否点击
    private canClick: boolean = true
    

    init(card: Card) {
        card.bindView(this)
        this.card = card
        this.selcted = false
    }

    onLoad() {
        this.node.on(TouchEventType.touchStart, this.onClickCard, this)
    }

    public flopCard(spriteFrame: cc.SpriteFrame) {
        this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame
    }

    private onClickCard() {
        if (!this.card.canClick) {
            // console.log('can not click')
            return
        }
        this.emit(ListenEventType.CLICK_CARD, this.card)
    }

    public isSelected() {
        return this.selcted
    }

    public setSelected(status: boolean) {
        this.selcted = status
    }

    // 设置能否点击
    public setCanClick(status: boolean) {
        this.canClick = status
    }
        
}
